    //
//  QYBookDetailListHeaderView.m
//  QingYue
//
//  Created by 崔明燃 on 2017/3/29.
//  Copyright © 2017年 com.lanou.product_A. All rights reserved.
//

#import "QYBookDetailListHeaderView.h"
#import "QYBookDetailModel.h"

@implementation QYBookDetailListHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.thumbView];
        [self addSubview:self.titleLable];
        [self addSubview:self.infoLabel];
        [self addSubview:self.focusBtn];
        [self addSubview:self.subLbl];
        [self addSubview:self.addBtn];
        [self subViewsLayouts];
        
        
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 230, KScreenW, 0.5)];
        lineView.backgroundColor = [UIColor lightGrayColor];
        [self addSubview:lineView];
    }
    return self;
}

- (void)focusClickAction:(UIButton *)sender {
    NSString *api = sender.selected? @"DelFollowBy":@"AddFollow";
    [self focusRequest:api];
}

- (void)focusRequest:(NSString *)api {
    _Lblock(_model.PropertyId,api);
}

- (void)setModel:(QYBookDetailModel *)model {
    _model = model;
    
    [_thumbView sd_setImageWithURL:[NSURL URLWithString:_model.Img] placeholderImage:[UIImage imageNamed:@"图书占位2"]];
    _titleLable.text = _model.Name;
    _infoLabel.text = [NSString stringWithFormat:@"作者:  %@\n\n出版社:  %@",_model.Author,_model.Publisher];
    
    _focusBtn.selected = _model.IsFollow.integerValue == 0? NO:YES;
}

#pragma mark - layout subview
- (void)subViewsLayouts {
    [_thumbView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(10);
        make.left.equalTo(self.mas_left).offset(15);
        make.width.equalTo(@140);
        make.height.equalTo(@180);
    }];
    
    [_titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(45);
        make.left.equalTo(_thumbView.mas_right).offset(15);
        make.height.equalTo(@30);
        make.right.equalTo(self.mas_right).offset(- 10);
    }];
    
    [_infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLable.mas_bottom).offset(15);
        make.left.equalTo(_thumbView.mas_right).offset(15);
        make.right.equalTo(self.mas_right).offset(- 10);
    }];
    
    [_focusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-30);
        make.bottom.mas_equalTo(-50);
    }];
    
    [_subLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.equalTo(self);
    }];
    
    [_addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.thumbView.mas_right).offset(15);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(20);
        make.centerY.equalTo(self.focusBtn);
    }];
}

- (UIButton *)addBtn {
    if (!_addBtn) {
        _addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _addBtn.backgroundColor = MyGreenColor;
        [_addBtn setTitle:@"添加" forState:UIControlStateNormal];
        [_addBtn setImage:[UIImage imageNamed:@"加号"] forState:UIControlStateNormal];
        _addBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
        _addBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        _addBtn.layer.cornerRadius = 5;
        _addBtn.layer.masksToBounds = YES;
    }
    return _addBtn;
}

#pragma mark - lazy load
- (UILabel *)subLbl {
    if (!_subLbl) {
        _subLbl = [[UILabel alloc] init];
        _subLbl.font = Font(15);
        _subLbl.text = @"   评论";
    }
    return _subLbl;
}

- (UIImageView *)thumbView {
    if (!_thumbView) {
        _thumbView = [[UIImageView alloc] init];
    }
    
    return _thumbView;
}

- (UILabel *)titleLable {
    if (!_titleLable) {
        _titleLable = [[UILabel alloc] init];
        _titleLable.font = Font(16);
    }
    
    return _titleLable;
}

- (UILabel *)infoLabel {
    if (!_infoLabel) {
        _infoLabel = [[UILabel alloc] init];
        _infoLabel.textColor = [UIColor lightGrayColor];
        _infoLabel.numberOfLines = 0;
        _infoLabel.font = Font(13);
    }
    
    return _infoLabel;
}


- (UIButton *)focusBtn {
    if (!_focusBtn) {
        _focusBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_focusBtn setImage:[UIImage imageNamed:@"xh_n"] forState:UIControlStateNormal];
        [_focusBtn setImage:[UIImage imageNamed:@"xh_s"] forState:UIControlStateSelected];
        [_focusBtn addTarget:self action:@selector(focusClickAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _focusBtn;
}

@end
